import { http } from "@/utils/http";

export type TokenInfo = {
  id: string;
  /** 用户名 */
  username: string;
  /** 当前登陆用户的角色 */
  roles: Array<string>;
  /** 当前登录用户的权限 */
  permissions: Array<string>;
  /** token 名称 */
  tokenKey: string;
  /** token 值 */
  accessToken: string;
  /** 用于调用刷新`accessToken`的接口时所需的`token` */
  refreshToken: string;
  /** token 过期时间（单位: 秒） */
  expires: number;
};

export type CaptchaRequestVo = {
  code: string;
  timestamp: number;
};

/** 登录 */
export const getLogin = (params?: object) => {
  return http.request<TokenInfo>("post", "/auth/securityLogin", params);
};

export const publicKey = () => {
  return http.request<string>("post", "/auth/publicKey");
};

/** 刷新token */
export const refreshTokenApi = (params?: object) => {
  return http.request<TokenInfo>("post", "/auth/refreshToken", params);
};

export const logout = () => {
  return http.request<string>("post", "/auth/logout");
};

export const checkCaptchaCode = (params?: CaptchaRequestVo) => {
  return http.request<boolean>("post", "/auth/check_captcha", params);
};
